package com.totem.base;

import org.springframework.cache.Cache;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CacheHolder {
    private static CacheHolder INSTANCE = new CacheHolder();
    private Cache cache;

    private CacheHolder(){}

    public void setCache(Cache cache){
        this.cache = cache;
    }
    public static CacheHolder instance(){
        return INSTANCE;
    }

    public void set(String key, Object value, long time){
        cache.putIfAbsent(key, value);
    }
    public Object get(String key){
        Cache.ValueWrapper vw = cache.get(key);
        if(vw==null){
            return null;
        }
        return vw.get();
    }
}
